{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# TensorFlow2.0教程-Boosted trees"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "本教程是使用决策树和tf.estimator API训练Gradient Boosting模型的端到端演练。 Boosted Trees模型是回归和分类中最受欢迎和最有效的机器学习方法之一。 这是一种集合技术，它结合了几种树模型的预测。\n",
    "\n",
    "Boosted Trees模型受到许多机器学习从业者的欢迎，因为它们可以通过最小的超参数调整实现令人印象深刻的性能。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.加载泰坦尼克数据集\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import absolute_import, division, print_function\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from IPython.display import clear_output\n",
    "\n",
    "# Load dataset.\n",
    "dftrain = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/train.csv')\n",
    "dfeval = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/eval.csv')\n",
    "y_train = dftrain.pop('survived')\n",
    "y_eval = dfeval.pop('survived')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "tf.random.set_seed(123)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据集由训练集和评估集组成：\n",
    "\n",
    "- `dftrain`和`y_train`是*training set*  - 模型用来学习的数据。\n",
    "- 模型根据*eval set*，`dfeval`和`y_eval`进行测试。\n",
    "\n",
    "数据集设定的特征如下：\n",
    "<table>\n",
    "  <tr>\n",
    "    <th>Feature Name</th>\n",
    "    <th>Description</th> \n",
    "  </tr>\n",
    "  <tr>\n",
    "    <td>sex</td>\n",
    "    <td>Gender of passenger</td> \n",
    "  </tr>\n",
    "  <tr>\n",
    "    <td>age</td>\n",
    "    <td>Age of passenger</td> \n",
    "  </tr>\n",
    "    <tr>\n",
    "    <td>n_siblings_spouses</td>\n",
    "    <td># siblings and partners aboard</td> \n",
    "  </tr>\n",
    "    <tr>\n",
    "    <td>parch</td>\n",
    "    <td># of parents and children aboard</td> \n",
    "  </tr>\n",
    "    <tr>\n",
    "    <td>fare</td>\n",
    "    <td>Fare passenger paid.</td> \n",
    "  </tr>\n",
    "    <tr>\n",
    "    <td>class</td>\n",
    "    <td>Passenger's class on ship</td> \n",
    "  </tr>\n",
    "    <tr>\n",
    "    <td>deck</td>\n",
    "    <td>Which deck passenger was on</td> \n",
    "  </tr>\n",
    "    <tr>\n",
    "    <td>embark_town</td>\n",
    "    <td>Which town passenger embarked from</td> \n",
    "  </tr>\n",
    "    <tr>\n",
    "    <td>alone</td>\n",
    "    <td>If passenger was alone</td> \n",
    "  </tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.探索数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>n_siblings_spouses</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "      <th>class</th>\n",
       "      <th>deck</th>\n",
       "      <th>embark_town</th>\n",
       "      <th>alone</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>Third</td>\n",
       "      <td>unknown</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>n</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>First</td>\n",
       "      <td>C</td>\n",
       "      <td>Cherbourg</td>\n",
       "      <td>n</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>Third</td>\n",
       "      <td>unknown</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>First</td>\n",
       "      <td>C</td>\n",
       "      <td>Southampton</td>\n",
       "      <td>n</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>male</td>\n",
       "      <td>28.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>8.4583</td>\n",
       "      <td>Third</td>\n",
       "      <td>unknown</td>\n",
       "      <td>Queenstown</td>\n",
       "      <td>y</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      sex   age  n_siblings_spouses  parch     fare  class     deck  \\\n",
       "0    male  22.0                   1      0   7.2500  Third  unknown   \n",
       "1  female  38.0                   1      0  71.2833  First        C   \n",
       "2  female  26.0                   0      0   7.9250  Third  unknown   \n",
       "3  female  35.0                   1      0  53.1000  First        C   \n",
       "4    male  28.0                   0      0   8.4583  Third  unknown   \n",
       "\n",
       "   embark_town alone  \n",
       "0  Southampton     n  \n",
       "1    Cherbourg     n  \n",
       "2  Southampton     y  \n",
       "3  Southampton     n  \n",
       "4   Queenstown     y  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dftrain.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>age</th>\n",
       "      <th>n_siblings_spouses</th>\n",
       "      <th>parch</th>\n",
       "      <th>fare</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>627.000000</td>\n",
       "      <td>627.000000</td>\n",
       "      <td>627.000000</td>\n",
       "      <td>627.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>29.631308</td>\n",
       "      <td>0.545455</td>\n",
       "      <td>0.379585</td>\n",
       "      <td>34.385399</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>12.511818</td>\n",
       "      <td>1.151090</td>\n",
       "      <td>0.792999</td>\n",
       "      <td>54.597730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.750000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>23.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>7.895800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>28.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>15.045800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>35.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>31.387500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>80.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>512.329200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              age  n_siblings_spouses       parch        fare\n",
       "count  627.000000          627.000000  627.000000  627.000000\n",
       "mean    29.631308            0.545455    0.379585   34.385399\n",
       "std     12.511818            1.151090    0.792999   54.597730\n",
       "min      0.750000            0.000000    0.000000    0.000000\n",
       "25%     23.000000            0.000000    0.000000    7.895800\n",
       "50%     28.000000            0.000000    0.000000   15.045800\n",
       "75%     35.000000            1.000000    0.000000   31.387500\n",
       "max     80.000000            8.000000    5.000000  512.329200"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dftrain.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(627, 264)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dftrain.shape[0], dfeval.shape[0] # 训练集，验证集数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f6448bfa128>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAFcBJREFUeJzt3X2MXXd95/H3dxOaUk9lJ032yutkO0FrUgW7GDyiqaBohrTUhIoAqthEEU1KugNSoqWrSK1DV6VdhJR2eWir7tJ1mzRhSz2hhEDWSUtTN9MsqwbwgBs7T40DBjxrbBIShwkoi+l3/7hn2tvp2DP3nvtw5pf3S7qae37nnHs+vvf6M3d+9ykyE0lSuf7VqANIkgbLopekwln0klQ4i16SCmfRS1LhLHpJKpxFL0mFs+glqXAWvSQV7sxRBwA499xzc3x8vKt9nnvuOdatWzeYQDWYq3tNzdbUXNDcbE3NBc3NVifX3Nzck5l53oobZuZpT8AFwH3Aw8BDwLur8XOAe4HHq59nV+MB/B5wCHgQeOVKx9i+fXt267777ut6n2EwV/eamq2puTKbm62puTKbm61OLmBfrtCvmbmqqZuTwA2ZeTFwCXBdRFwM7AT2ZuZmYG+1DPAGYHN1mgY+sopjSJIGZMWiz8yjmfnF6vy3gUeATcDlwG3VZrcBb67OXw58tPqF8wCwISI29j25JGlVIrv49MqIGAfuB7YAX8vMDdV4AE9n5oaI2APclJmfrdbtBX41M/ctuaxp2o/4abVa22dmZroKvrCwwNjYWFf7DIO5utfUbE3NBc3N1tRc0NxsdXJNTU3NZebEihuuZn6n+mUwBswBb62Wn1my/unq5x7gNR3je4GJ0122c/SD19Rcmc3N1tRcmc3N1tRcmc3N1pQ5eiLiRcAdwMcy85PV8LHFKZnq5/FqfJ72E7iLzq/GJEkjsGLRV9MyNwOPZOaHOlbdBVxdnb8a+HTH+C9E2yXAicw82sfMkqQurOZ19K8G3g4ciIj91dh7gJuAj0fEt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R35Yd+bYB+6rb9FPA2U3IRnta5ClgfcdYE3L9JvBodf//n8BZw7if+c5YSSrcWpu6kSR1yaKXpMJZ9JJUOItekgpn0UtS4Sx6SSqcRS9JhbPoJalw/x8MqdwquVi2jAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 年龄分布\n",
    "dftrain.age.hist(bins=20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f6448b71320>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAD8CAYAAABpcuN4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAADKJJREFUeJzt3H+sZHdZx/HPQ7fdmhaL0IZsWvBS3EhIgbaWiooEEPnRNRQEEyKBkhAaRVFjGi0SSU1FK4iiCUqqYlFREMSAEIJIa0wQW3ftj21tF6pdI7XSIKHUNKlKv/4xZ+F6uffZ7vbunHvr65VMdubM6cwz35vZ954zc1tjjADARh4x9wAAbG1CAUBLKABoCQUALaEAoCUUALSEAoCWUADQEgoAWjvmHmAznHrqqWNlZWXuMQC2lX379n1xjHHa4fZ7WIRiZWUle/funXsMgG2lqv7lwezn1BMALaEAoCUUALSEAoCWUADQEgoAWkIBQEsoAGgJBQAtoQCgJRQAtIQCgJZQANASCgBaQgFASygAaAkFAC2hAKAlFAC0hAKAllAA0BIKAFpCAUBLKABoCQUALaEAoLVj7gE2w/4778nKpR+bewxY18Er9sw9AjwkjigAaAkFAC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311Zat2meLye5Jsl3ZXHa5tD/Jmj1839ttun+U5L8xxJne+F0Km+MMe5P8vuZZ92+J8mLq+pgFqfOn5vkN7LF1i3Z3qH4+yS7p28InJDFhzsfmWuYqjqpqh556HqS5ye5eZrpomm3i5J8eJ4Jk2aWjyR59fSNj2ckuWfVaZalWHMe+KVZrN2h2V4xfePjCUl2J7nuGM5RSX4vya1jjF9bddesa7fRXFth3arqtKp61HT9m5J8fxafoVyT5OXTbmvX7NBavjzJ1dNR2rJmu21V9CuLzwBWr9tS3gtjjDeOMc4YY6xk8ffX1WOMV2YLrNt6w27bSxbfUPhsFudD3zTzLGdm8S2TG5PccmieLM4hfirJ55L8VZJHL2meP8niVMR/Z3Ge87UbzZLFNzzeOa3j/iTnzTDbH07PfVMWb4hdq/Z/0zTbgSQvOsazPTOL00o3Jblhulww99o1c82+bkmemuT6aYabk7x51Xviuiw+SP9Akp3T9hOn27dP9585w2xXT+t2c5I/yte/GbXU98KqOZ+dr3/rafZ1W3vxm9kAtLbzqScAlkAoAGgJBQAtoQCgJRQAtIQCgJZQANASCgBa/ws5zjf/WUrDRgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 男女比例\n",
    "dftrain.sex.value_counts().plot(kind='barh')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f64448b9908>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAAD8CAYAAABkbJM/AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwO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9zrquqDw/BUzPt82adl3o+rqgeBTwIvYXTI5vivUZqd7/Hsw+0bgAdWOerXmZX7ouHwYFXVY8C7WYY5XwuF8U/A1uGdDKcxOvn04TFnWlCSb0xyxvFt4IeAw4wyXzbsdhnwl+NJ2LJQ1g8DPz+8C+PFwEOzDqFMhDnHal/FaO5hlP01wztfngNsBW5e7XwwehcL8CfA56vqD2bdNPHzvlD2KZn3jUnOHLafCvwgo3MwnwR2DrvNnffj34+dwCeGld+qWiD3F2b94yKMzrvMnvOlvV7GcVZ/uS+Mzvp/kdHxxsvHnWeRrFsYvSvkAHDr8byMjn3+LXA78HHgGePOOuR6P6NDCP/D6FjnLy6UldG7Lq4avg+HgB0TmP3aIdvB4S/Opln7Xz5kvw14xRhzX8DocNNBYP9wuXga5v0E2adh3p8P/POQ8TDwxmF8C6MSuwP4c2D9MP6U4fodw+1bJiz3J4Y5Pwy8j6+9k2rJrxf/p7ckqWUtHJKSJK0CC0OS1GJhSJJaLAxJUouFIUlqsTAkSS0WhiSpxcKQJLX8HzN/2PLgtLgeAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 大部分为三等顾客\n",
    "dftrain['class'].value_counts().plot(kind='barh')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaoAAAD8CAYAAAAmL+CoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAEwtJREFUeJzt3X/U3nV93/HnywCJLQoFMpoF6j0glAONppIyo8CAsh0mHhmVmalnwvQ0dXVn4uosnTut3Q47WOpACrajG6KbpU4L2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ZlBJkrpmUEmSumZQSZK6ZlBJkrpmUEmSumZQSZK6ZlBJkrr2/wBTZj6rlI3D/gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 大多数乘客从南安普敦出发。\n",
    "dftrain['embark_town'].value_counts().plot(kind='barh');"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 0, '% survive')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAEKCAYAAAAvlUMdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAD7JJREFUeJzt3X2sZHV9x/H3B1eXiohWMF1B3UrXIkUQQXxISyC1aNkIKIhYtZJSiA/FGIsp1mqoVN2KtrZVq9harNGCUFJRVKoCGimgizwVEUTZRpC0PiJKtALf/jFn67DcZWcfvjNzd9+vZJJz5v7unM+ce+9+7jm/veekqpAkaUvbbtYBJElbJwtGktTCgpEktbBgJEktLBhJUgsLRpLUwoKRJLWwYCRJLSwYSVKLJbMOMEs777xzLV++fNYxJGlRueKKK75bVbtsaNw2XTDLly9n9erVs44hSYtKkv+aZJynyCRJLSwYSVILC0aS1MKCkSS1sGAkSS0sGElSCwtGktTCgpEktbBgJEktLBhJUgsLRpLUwoKRJLWwYCRJLSwYSVILC0aS1MKCkSS1sGAkSS0sGElSCwtGktTCgpEktbBgJEktLBhJUgsLRpLUwoKRJLWwYCRJLSwYSVKLJbMOMEvX3no7y08+f9Yx5t6aVStnHUHSIuQRjCSphQUjSWphwUiSWl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OMH2pc1iwUiboKpur6qVVbU/8BVG1zY7J8n7h0vYP32BT7sEOCPJ8Yxu9rQhdwP/OmzvLuDTwHOGo6WVwMfWyXQl8Mgkj0qyD/CDqvoWcMjwuHLIugfTvfCjtlFLZh1A2gq8AXgzo3mZLzK6cd25wLPGB1XVy5I8lVE5XJFkP+Au7v2L3vZjyz+te1/C/Uzgj4DvM7pQ5x0LZDkbOAr4FUZHNDC6Ltdbq+p9m/b2pE3jEYy0GZKsAHarqosZzcncw+gugL+0wNjdq+ryqnoj8B1Gl0pfAzwpyXbDjbsOuJ/NfR54MqO7Na57emytsxhdFfwoRmUDcAHwB0keMuTYNckjN+Z9SpvCIxhp87yZ0T1wYHRPj38DTmY037Ku04ZCCvA5RleoBbiZ0VV/r2d0CmtBVXX3MLF/LPDS9Yy5LsmOwK1Vddvw3L8neQJw6XA38B8DLwamfRthbWO8mrIkqYWnyCRJLSwYSVILC0aS1MKCkSS1sGAkSS0sGElSCwtGktTCgpEktfg/6IUEFuljTQAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 与男性相比，女性存活的机率要高得多。 这显然是该模型的预测特征\n",
    "pd.concat([dftrain, y_train], axis=1).groupby('sex').survived.mean().plot(kind='barh').set_xlabel('% survive')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.构造输入特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "fc = tf.feature_column\n",
    "CATEGORICAL_COLUMNS = ['sex', 'n_siblings_spouses', 'parch', 'class', 'deck', \n",
    "                       'embark_town', 'alone']\n",
    "NUMERIC_COLUMNS = ['age', 'fare']\n",
    "  \n",
    "def one_hot_cat_column(feature_name, vocab):\n",
    "    return tf.feature_column.indicator_column(\n",
    "      tf.feature_column.categorical_column_with_vocabulary_list(feature_name,\n",
    "                                                 vocab))\n",
    "feature_columns = []\n",
    "for feature_name in CATEGORICAL_COLUMNS:\n",
    "    # Need to one-hot encode categorical features.\n",
    "    vocabulary = dftrain[feature_name].unique()\n",
    "    feature_columns.append(one_hot_cat_column(feature_name, vocabulary))\n",
    "\n",
    "for feature_name in NUMERIC_COLUMNS:\n",
    "    feature_columns.append(tf.feature_column.numeric_column(feature_name,\n",
    "                                           dtype=tf.float32))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以查看要素列生成的转换。 例如，以下是在单个示例中使用`indicator_column`时的输出："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Feature value: \"Third\"\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: Logging before flag parsing goes to stderr.\n",
      "W0331 19:59:16.792093 140069985818368 deprecation.py:323] From /home/czy/anaconda3/envs/tf2_0/lib/python3.6/site-packages/tensorflow/python/ops/lookup_ops.py:1347: to_int64 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use `tf.cast` instead.\n",
      "W0331 19:59:16.879169 140069985818368 deprecation.py:323] From /home/czy/anaconda3/envs/tf2_0/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py:4307: IndicatorColumn._variable_shape (from tensorflow.python.feature_column.feature_column_v2) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "The old _FeatureColumn APIs are being deprecated. Please use the new FeatureColumn APIs instead.\n",
      "W0331 19:59:16.880531 140069985818368 deprecation.py:323] From /home/czy/anaconda3/envs/tf2_0/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py:4362: VocabularyListCategoricalColumn._num_buckets (from tensorflow.python.feature_column.feature_column_v2) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "The old _FeatureColumn APIs are being deprecated. Please use the new FeatureColumn APIs instead.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "One-hot encoded:  [[0. 0. 1.]]\n"
     ]
    }
   ],
   "source": [
    "example = dict(dftrain.head(1))\n",
    "class_fc = tf.feature_column.indicator_column(tf.feature_column.categorical_column_with_vocabulary_list('class', ('First', 'Second', 'Third')))\n",
    "print('Feature value: \"{}\"'.format(example['class'].iloc[0]))\n",
    "print('One-hot encoded: ', tf.keras.layers.DenseFeatures([class_fc])(example).numpy())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以一起查看所有要素列转换："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "W0331 20:00:18.112254 140069985818368 deprecation.py:323] From /home/czy/anaconda3/envs/tf2_0/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py:2758: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use `tf.cast` instead.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[22.  ,  1.  ,  0.  ,  1.  ,  0.  ,  0.  ,  1.  ,  0.  ,  0.  ,\n",
       "         0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  1.  ,  0.  ,  0.  ,  0.  ,\n",
       "         7.25,  1.  ,  0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  1.  ,\n",
       "         0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  1.  ,  0.  ]], dtype=float32)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.keras.layers.DenseFeatures(feature_columns)(example).numpy()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "接下来，需要创建输入函数。 这些将指定如何将数据读入我们的模型以进行训练和推理。 我们使用[`tf.data`](https://www.tensorflow.org/api_docs/python/tf/data)\n",
    "API中的`from_tensor_slices`方法直接从Pandas读取数据。 这适用于较小的内存数据集。 对于较大的数据集，tf.data API支持各种文件格式（包括[csv](https://www.tensorflow.org/api_docs/python/tf/data/experimental/make_csv_dataset))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Use entire batch since this is such a small dataset.\n",
    "NUM_EXAMPLES = len(y_train)\n",
    "\n",
    "def make_input_fn(X, y, n_epochs=None, shuffle=True):\n",
    "    def input_fn():\n",
    "        dataset = tf.data.Dataset.from_tensor_slices((dict(X), y))\n",
    "        if shuffle:\n",
    "            dataset = dataset.shuffle(NUM_EXAMPLES)\n",
    "        # For training, cycle thru dataset as many times as need (n_epochs=None).    \n",
    "        dataset = dataset.repeat(n_epochs)\n",
    "        # In memory training doesn't use batching.\n",
    "        dataset = dataset.batch(NUM_EXAMPLES)\n",
    "        return dataset\n",
    "    return input_fn\n",
    "\n",
    "# Training and evaluation input functions.\n",
    "train_input_fn = make_input_fn(dftrain, y_train)\n",
    "eval_input_fn = make_input_fn(dfeval, y_eval, shuffle=False, n_epochs=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.训练和验证模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在训练Boosted Trees模型之前，让我们首先训练一个线性分类器（逻辑回归模型）。 最好的做法是从更简单的模型开始建立基准。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "accuracy                  0.765152\n",
      "accuracy_baseline         0.625000\n",
      "auc                       0.832844\n",
      "auc_precision_recall      0.789631\n",
      "average_loss              0.478908\n",
      "label/mean                0.375000\n",
      "loss                      0.478908\n",
      "precision                 0.703297\n",
      "prediction/mean           0.350790\n",
      "recall                    0.646465\n",
      "global_step             100.000000\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "linear_est = tf.estimator.LinearClassifier(feature_columns)\n",
    "\n",
    "# Train model.\n",
    "linear_est.train(train_input_fn, max_steps=100)\n",
    "\n",
    "# Evaluation.\n",
    "result = linear_est.evaluate(eval_input_fn)\n",
    "clear_output()\n",
    "print(pd.Series(result))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "接下来让我们训练一下Boosted Trees模型。 对于增强树，支持回归（BoostedTreesRegressor）和分类（BoostedTreesClassifier）。 由于目标是预测一个类，所以我们使用BoostedTreesClassifier。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "accuracy                  0.829545\n",
      "accuracy_baseline         0.625000\n",
      "auc                       0.873003\n",
      "auc_precision_recall      0.858218\n",
      "average_loss              0.410594\n",
      "label/mean                0.375000\n",
      "loss                      0.410594\n",
      "precision                 0.793478\n",
      "prediction/mean           0.381616\n",
      "recall                    0.737374\n",
      "global_step             100.000000\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# Since data fits into memory, use entire dataset per layer. It will be faster.\n",
    "# Above one batch is defined as the entire dataset. \n",
    "n_batches = 1\n",
    "est = tf.estimator.BoostedTreesClassifier(feature_columns,\n",
    "                                          n_batches_per_layer=n_batches)\n",
    "\n",
    "# The model will stop training once the specified number of trees is built, not \n",
    "# based on the number of steps.\n",
    "est.train(train_input_fn, max_steps=100)\n",
    "\n",
    "# Eval.\n",
    "result = est.evaluate(eval_input_fn)\n",
    "clear_output()\n",
    "print(pd.Series(result))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "用训练好的模型进行预测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f64164129b0>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
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rbl2Zr9w7AE4CLk6xh0Ie6ap4PGLf5t14LrKqqX1fVDcD/YxAM81mbdp8InA1QVd8AtmVwY7YtWae35pmvQdDmNhWrgGXN9AuBr1Uz6jKPzdruJAcBH2QQAltCnzHM0u6q+mlVLaqqpVW1lMHYyNFVtXo85c6JNv+Nf57B2QBJFjHoKrp+lEV2oE27bwIOB0jyeAZBsG6kVY7eKuAPm6uHngL8tKpum6s3n5ddQzXDbSqSvB1YXVWrgNMZnDJex2AQ5sXjq3hutGz3/wYeBny6GRu/qaqOHlvRc6Blu7coLdv898BzklwNPAD8aVXN67Pelu1+I/ChJP+NwcDxCfP9j7wkn2QQ6ouasY+Tga0BquoDDMZCjgSuA34JvGxOjz/PPz9J0iaar11DkqQ5YhBIUs8ZBJLUcwaBJPWcQSBJPWcQSFLPGQSS1HP/H6Af/DWFM1tyAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "pred_dicts = list(est.predict(eval_input_fn))\n",
    "probs = pd.Series([pred['probabilities'][1] for pred in pred_dicts])\n",
    "\n",
    "probs.plot(kind='hist', bins=20, title='predicted probabilities')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "观察roc得分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3XmcVnXd//HXm2ETGBYBRQUEDUPMUiPcKrHU3M0y07IyK3+3ZvvtT81uM+t322aLZRqVkZZpaguVZWkqZS7gEi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RvHpf8SES+ThN2v0309QBJqrbmcpLfcR4BlZdP/CJy6paEZ+DQwPm0Yn0nSEG22FfeSapaStDYitrnbx6wr8ZmCmZmCBli7AAAAKUlEQVSV+EzBzMxKfKZgZmYlDgUzMytxKJiZWYlDwczMShwKZmZW8v8Bbb9d/eI2pX4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.metrics import roc_curve\n",
    "from matplotlib import pyplot as plt\n",
    "\n",
    "fpr, tpr, _ = roc_curve(y_eval, probs)\n",
    "plt.plot(fpr, tpr)\n",
    "plt.title('ROC curve')\n",
    "plt.xlabel('false positive rate')\n",
    "plt.ylabel('true positive rate')\n",
    "plt.xlim(0,)\n",
    "plt.ylim(0,);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
